<?php


namespace app\admin\model;


use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\TemplateProcessor;
use think\Db;
use think\Model;

class ContractModel extends BaseModel
{
    protected $name='contract';



    //订单号   产品编号
    public static function get_contract_sn(){
        $count =self::order('contract_id DESC')->find();
        $time =date('Y');
        if(date('Y',$count['add_time'])==$time){
            $number =  'JZ-370126-'.$time.'-'.str_pad(substr($count['contract_sn'],15)+1, 6, '0', STR_PAD_LEFT);
        }else{
            $number =  'JZ-370126-'.$time.'-'.str_pad(0+1, 6, '0', STR_PAD_LEFT);
        }
        return $number;
    }
    //订单号   产品编号
    public static function get_qm_contract_sn(){
        $count = self::where('contract_sn','like','%JZQM%')->order('contract_id DESC')->find();
//        $count =self::order('contract_id DESC')->find();
        $time =date('Y');
        if(date('Y',$count['add_time'])==$time){
            $number =  'JZQM-370126-'.$time.'-'.str_pad(substr($count['contract_sn'],17)+1, 6, '0', STR_PAD_LEFT);
        }else{
            $number =  'JZQM-370126-'.$time.'-'.str_pad(0+1, 6, '0', STR_PAD_LEFT);
        }
//        exit(json_encode(substr($count['contract_sn'],17)));
        return $number;
    }


    /**
     * @param $servicemove_id 迁墓服务id
     * @param $order_id       订单id
     * @param $contract_sn    合同编号
     * @param string $sign_time
     * @return array
     */
    public function content_temp_quanmu($servicemove_id,$order_id,$contract_sn=''){

        $field = 'o.customer_id,o.sign_time,p.tomb_num,p.tomb_address,p.layer_num,p.tomb_bit_number,p.cemetery_id';
        $result_order = Db::name('order')->alias('o')->field($field)
            ->join("dj_tombarea_row_col c","o.tomb_id = c.colID","left")
            ->join("dj_tombarea_information_product p","o.tomb_product_id = p.id","left")
            ->where(['o.order_id'=>$order_id])->find();
        $sign_time = $result_order['sign_time'];
        $customer_id = $result_order['customer_id'];

        $customer_info = Db::name("customer_info")->where(['id'=>$customer_id])->find();
        $cart_type = cart_type('cart',$customer_info['cart_type']);

        $tomb_region = self::getSupName($result_order['cemetery_id']);

        $region='';
        foreach ($tomb_region as $k=>&$v){
            if ($v['parent_id']!=0) {
                $region = $v['name'] . $region;
            }
        }

        $tomb_region_ceng = $result_order['tomb_address'].$result_order['layer_num'].$result_order['tomb_bit_number'];

        $move_info = ServiceMoveModel::where(['id'=>$servicemove_id])->find();

        $templateProcessor = new TemplateProcessor('document/contract/qianmu.docx');
        $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号
        $templateProcessor->setValue('customer_buyer_name', $customer_info['buyer_name']); //
        $templateProcessor->setValue('customer_buyer_phone', $customer_info['buyer_phone']); //
        $templateProcessor->setValue('customer_customer_account', $customer_info['customer_account']); //
        $templateProcessor->setValue('customer_customer_address', $customer_info['customer_address']); //
        $templateProcessor->setValue('cart_type', $cart_type); //

        $templateProcessor->setValue('tomb_region_qu', $region); //
        $templateProcessor->setValue('tomb_region_ceng', $tomb_region_ceng); //
        $move_time = $move_info['move_time']?$move_info['move_time']:'';

        $deceased  = ArchivesDeceasedModel::where(['servicemove_id'=>$servicemove_id])->select();

        $templateProcessor->setValue('move_deceased_name1', $deceased[0]['deceased_name']?$deceased[0]['deceased_name']:''); //
        $templateProcessor->setValue('move_deceased_name2', isset($deceased[1]['deceased_name'])?$deceased[1]['deceased_name']:''); //

        $templateProcessor->setValue('m_nian', $move_time ? date('Y', $move_time) : ''); // 年
        $templateProcessor->setValue('m_yue', $move_time ? date('m', $move_time) : ''); // 月
        $templateProcessor->setValue('m_ri', $move_time ? date('d', $move_time) : ''); // 日


        $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
        $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
        $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日

        $file = 'upload/archives/' . $result_order['tomb_num'] . '/contract/qm-' . $contract_sn;
        if (!file_exists('upload/archives/' . $result_order['tomb_num'] . '/')) {
            mkdir('upload/archives/' . $result_order['tomb_num'] . '/');
        }
        if (!file_exists('upload/archives/' . $result_order['tomb_num'] . '/contract/')) {
            mkdir('upload/archives/' . $result_order['tomb_num'] . '/contract/');
        }
//        $file = 'temp/doc/'.$contract_sn.'-'.$result_order['tomb_num'].'';
        $templateProcessor->saveAs($file . '.docx');
        $phpWord = \PhpOffice\PhpWord\IOFactory::load($file . '.docx');
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
        $xmlWriter->save($file . '.html');
        return ['doc' => $file . '.docx', 'html' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . $file . '.html'];
    }
    //寄存协议
    public function content_temp_xieyi($order_id,$contract_sn,$sign_time='')
    {
        $field = 'o.*,p.*,c.rows_num,column_num';
        $result_order = Db::name('order')->alias('o')->field($field)
            ->join("dj_tombarea_row_col c", "o.tomb_id = c.colID", "left")
            ->join("dj_tombarea_information_product p", "o.tomb_product_id = p.id", "left")
            ->where(['o.order_id' => $order_id])->find();
        $customer_id = $result_order['customer_id'];
        $sign_time = $result_order['sign_time'];
        $customer_info = Db::name("customer_info")->where(['id' => $customer_id])->find();
        $cart_type = cart_type('cart', $customer_info['cart_type']);

        $tomb_region = self::getSupName($result_order['cemetery_id']);
        $region='';
        foreach ($tomb_region as $k=>&$v){
            if ($v['parent_id']!=0) {
                $region = $v['name'] . $region;
            }
        }
        $tomb_address = $region.$result_order['tomb_address'].$result_order['layer_num'].$result_order['tomb_bit_number'];

        switch ($result_order['tomb_type']) {
            case 1:
                break;
            case 2:
                break;
            case 3:
                $templateProcessor = new TemplateProcessor('document/contract/shengtaimu.docx');
                $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号
                $templateProcessor->setValue('customer_buyer_name', $customer_info['buyer_name']); //
                $templateProcessor->setValue('customer_buyer_phone', $customer_info['buyer_phone']); //
                $templateProcessor->setValue('customer_customer_account', $customer_info['customer_account']); //
                $templateProcessor->setValue('customer_customer_address', $customer_info['customer_address']); //
                $templateProcessor->setValue('cart_type', $cart_type); //

                $templateProcessor->setValue('customer_deceased_name', ' '); //

                $templateProcessor->setValue('tomb_region_qu', $tomb_address);//所在区域
                $templateProcessor->setValue('tomb_num', $result_order['tomb_num']);  // 墓位编号

                $templateProcessor->setValue('convergence', $result_order['convergence']); // 销售价格
                $templateProcessor->setValue('danjia', $result_order['selling_price']); // 销售价格
                $templateProcessor->setValue('zhengcebutie', $result_order['discount_ratio']); // 政策补贴
                $templateProcessor->setValue('yingshou_price', $result_order['closing_price']); // 应收
                $templateProcessor->setValue('shishou_price', $result_order['closing_price']); // 实收
                $templateProcessor->setValue('heji_price', $result_order['closing_price']); // 总计

                $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
                $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
                $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日
                break;
            case 4:
                break;
        }

        $file = 'upload/archives/' . $result_order['tomb_num'] . '/contract/xieyi-' . $contract_sn;
        if (!file_exists('upload/admin/' . $result_order['tomb_num'] . '/')) {
            mkdir('upload/admin/' . $result_order['tomb_num'] . '/');
        }
        if (!file_exists('upload/admin/' . $result_order['tomb_num'] . '/contract/')) {
            mkdir('upload/admin/' . $result_order['tomb_num'] . '/contract/');
        }
//        $file = 'temp/doc/'.$contract_sn.'-'.$result_order['tomb_num'].'';
        $templateProcessor->saveAs($file . '.docx');
        $phpWord = \PhpOffice\PhpWord\IOFactory::load($file . '.docx');
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
        $xmlWriter->save($file . '.html');
        return ['doc' => $file . '.docx', 'html' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . $file . '.html'];
    }

    public function content_temp_hetong($order_id,$contract_sn,$sign_time=''){
        $field = 'o.*,p.*,c.rows_num,column_num';
        $result_order = Db::name('order')->alias('o')->field($field)
            ->join("dj_tombarea_row_col c", "o.tomb_id = c.colID", "left")
            ->join("dj_tombarea_information_product p", "o.tomb_product_id = p.id", "left")
            ->where(['o.order_id' => $order_id])->find();
        $sign_time = $result_order['sign_time'];
        $customer_info = Db::name("customer_info")->where(['id' => $customer_id])->find();
        $cart_type = cart_type('cart', $customer_info['cart_type']);

        $tomb_region = self::getSupName($result_order['cemetery_id']);
        $tomb_region_ceng = '';
        $tomb_region_qu = '';
        $tomb_region_yuan = '';
        foreach ($tomb_region as $k => &$v) {
            if ($v['type'] == '层') {
                $tomb_region_ceng = $v['name'];
            } elseif ($v['type'] == '区') {
                $tomb_region_qu = $v['name'];
            } elseif ($v['type'] == '园') {
                $tomb_region_yuan = $v['name'];
            } else {
                $region = '';
            }
        }
        $templateProcessor = new TemplateProcessor('document/contract/shangpinmu.docx');
        $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号

        $templateProcessor->setValue('customer_buyer_name',$customer_info['buyer_name']); //
        $templateProcessor->setValue('customer_buyer_phone',$customer_info['buyer_phone']); //
        $templateProcessor->setValue('customer_customer_account',$customer_info['customer_account']); //
        $templateProcessor->setValue('customer_customer_address',$customer_info['customer_address']); //

        $templateProcessor->setValue('funeral_1',$result_order['funeral']=='墓穴葬'?'√':''); //
        $templateProcessor->setValue('funeral_2',$result_order['funeral']=='树葬'?'√':''); //
        $templateProcessor->setValue('funeral_3',$result_order['funeral']=='草坪葬'?'√':''); //
        $templateProcessor->setValue('funeral_4',$result_order['funeral']=='花坛葬'?'√':''); //
        $templateProcessor->setValue('funeral_5',$result_order['funeral']=='壁葬'?'√':''); //
        $templateProcessor->setValue('funeral_6',$result_order['funeral']=='4'?'√':''); //
        $templateProcessor->setValue('funeral_7',$result_order['funeral']=='其他'?'√':$result_order['funeral']); //

        $templateProcessor->setValue('tomb_region_qu',$tomb_region_qu);//所在区域
        $templateProcessor->setValue('tomb_region_yuan',$tomb_region_yuan);//所在区域
        $templateProcessor->setValue('tomb_region_ceng',$tomb_region_ceng?$tomb_region_ceng:$result_order['layer_num']);//所在区域
        $templateProcessor->setValue('row_num',$result_order['rows_num']);  //排
        $templateProcessor->setValue('tomb_bit_number',$result_order['column_num']);  // 位
        $templateProcessor->setValue('tomb_num',$result_order['tomb_num']);  // 墓位编号

        $templateProcessor->setValue('tomb_regulation_1',$result_order['tomb_regulation']==1?'√':''); // 单穴、双穴合墓、多穴合墓
        $templateProcessor->setValue('tomb_regulation_2',$result_order['tomb_regulation']==2?'√':''); // 单穴、双穴合墓、多穴合墓
        $templateProcessor->setValue('tomb_regulation_3',$result_order['tomb_regulation']==3?'√':''); // 单穴、双穴合墓、多穴合墓

        $templateProcessor->setValue('closing_price',$result_order['closing_price']); // 总计
        $templateProcessor->setValue('closing_price_num',convertAmountToCn($result_order['closing_price'],0)); // 总计

        $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
        $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
        $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日

        $file =  'upload/archives/'.$result_order['tomb_num'].'/contract/'.$contract_sn;
        if (!file_exists('upload/admin/'.$result_order['tomb_num'].'/')){
            mkdir('upload/admin/'.$result_order['tomb_num'].'/');
        }
        if (!file_exists('upload/admin/'.$result_order['tomb_num'].'/contract/')){
            mkdir('upload/admin/'.$result_order['tomb_num'].'/contract/');
        }
//        $file = 'temp/doc/'.$contract_sn.'-'.$result_order['tomb_num'].'';
        $templateProcessor->saveAs($file.'.docx');
        $phpWord = \PhpOffice\PhpWord\IOFactory::load($file.'.docx');
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
        $xmlWriter ->save($file.'.html');//$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].
        return ['doc'=>$file.'.docx','html'=>'/'.$file.'.html'];


    }
    public static function content_temp($order_id,$contract_sn,$sign_time=''){

        $field = 'o.*,p.*,c.rows_num,column_num';
        $result_order = Db::name('order')->alias('o')->field($field)
            ->join("dj_tombarea_row_col c","o.tomb_id = c.colID","left")
            ->join("dj_tombarea_information_product p","o.tomb_product_id = p.id","left")
            ->where(['o.order_id'=>$order_id])->find();
        $sign_time = !empty($sign_time)?$sign_time:$result_order['sign_time'];
        $customer_id = $result_order['customer_id'];

        $customer_info = Db::name("customer_info")->where(['id'=>$customer_id])->find();
        $cart_type = cart_type('cart',$customer_info['cart_type']);

        $tomb_region = self::getSupName($result_order['cemetery_id']);
        $region='';
        foreach ($tomb_region as $k=>&$v){
            if ($v['parent_id']!=0) {
                $region = $v['name'] . $region;
            }
        }
        $tomb_address = $region.$result_order['tomb_address'].$result_order['layer_num'].$result_order['tomb_bit_number'];

        switch ($result_order['tomb_type']){
            case 1:
                $templateProcessor = new TemplateProcessor('document/contract/shangpinmu.docx');
                $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号

                $templateProcessor->setValue('customer_buyer_name',$customer_info['buyer_name']); //
                $templateProcessor->setValue('customer_buyer_phone',$customer_info['buyer_phone']); //
                $templateProcessor->setValue('customer_customer_account',$customer_info['customer_account']); //
                $templateProcessor->setValue('customer_customer_address',$customer_info['customer_address']); //

                $templateProcessor->setValue('funeral_1',$result_order['funeral']=='墓穴葬'?'√':''); //
                $templateProcessor->setValue('funeral_2',$result_order['funeral']=='树葬'?'√':''); //
                $templateProcessor->setValue('funeral_3',$result_order['funeral']=='草坪葬'?'√':''); //
                $templateProcessor->setValue('funeral_4',$result_order['funeral']=='花坛葬'?'√':''); //
                $templateProcessor->setValue('funeral_5',$result_order['funeral']=='壁葬'?'√':''); //
                $templateProcessor->setValue('funeral_6',$result_order['funeral']=='4'?'√':''); //
                $templateProcessor->setValue('funeral_7',$result_order['funeral']=='其他'?'√':$result_order['funeral']); //

                $templateProcessor->setValue('tomb_region_qu',$tomb_address);//所在区域
                $templateProcessor->setValue('tomb_num',$result_order['tomb_num']);  // 墓位编号

                $templateProcessor->setValue('tomb_regulation_1',$result_order['tomb_regulation']==1?'√':''); // 单穴、双穴合墓、多穴合墓
                $templateProcessor->setValue('tomb_regulation_2',$result_order['tomb_regulation']==2?'√':''); // 单穴、双穴合墓、多穴合墓
                $templateProcessor->setValue('tomb_regulation_3',$result_order['tomb_regulation']==3?'√':''); // 单穴、双穴合墓、多穴合墓

                $templateProcessor->setValue('closing_price',$result_order['closing_price']); // 总计
                $templateProcessor->setValue('closing_price_num',convertAmountToCn($result_order['closing_price'],0)); // 总计

                $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
                $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
                $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日


                break;
            case 2:
                $templateProcessor = new TemplateProcessor('document/contract/yishumu.docx');
                $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号
                $templateProcessor->setValue('customer_buyer_name',$customer_info['buyer_name']); //
                $templateProcessor->setValue('customer_buyer_phone',$customer_info['buyer_phone']); //
                $templateProcessor->setValue('customer_customer_account',$customer_info['customer_account']); //
                $templateProcessor->setValue('customer_customer_address',$customer_info['customer_address']); //

                $templateProcessor->setValue('tomb_region_qu',$tomb_address);//所在区域
                $templateProcessor->setValue('tomb_num',$result_order['tomb_num']);  // 墓位编号

                $templateProcessor->setValue('tomb_regulation',$result_order['tomb_regulation']==1?"单穴":$result_order['tomb_regulation']==2?"双穴合墓":$result_order['tomb_regulation']==3?"多穴合墓":""); // 单穴、双穴合墓、多穴合墓

                $templateProcessor->setValue('sheji_num',$result_order['design']); // 艺术墓碑{设计几套}
                $templateProcessor->setValue('tombstone_h',$result_order['tombstone_h']); // 艺术墓 - 长
                $templateProcessor->setValue('tombstone_w',$result_order['tombstone_w']); // 艺术墓 - 宽
                $templateProcessor->setValue('subscription_area',$result_order['subscription_area']); //面积
                $templateProcessor->setValue('tomb_regulation_1',$result_order['tomb_regulation']==1?'√':''); // 单穴、双穴合墓、多穴合墓
                $templateProcessor->setValue('tomb_regulation_2',$result_order['tomb_regulation']==2?'√':''); // 单穴、双穴合墓、多穴合墓
                $templateProcessor->setValue('tomb_regulation_3',$result_order['tomb_regulation']==3?'√':''); // 单穴、双穴合墓、多穴合墓
                $templateProcessor->setValue('tomb_regulation_4', ''); // 单穴、双穴合墓、多穴合墓


                $templateProcessor->setValue('closing_price',$result_order['closing_price']); // 总计
                $templateProcessor->setValue('closing_price_num',convertAmountToCn($result_order['closing_price'],0)); // 总计

                $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
                $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
                $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日
                break;
            case 3:
                $templateProcessor = new TemplateProcessor('document/contract/shangpinmu.docx');
                $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号

                $templateProcessor->setValue('customer_buyer_name',$customer_info['buyer_name']); //
                $templateProcessor->setValue('customer_buyer_phone',$customer_info['buyer_phone']); //
                $templateProcessor->setValue('customer_customer_account',$customer_info['customer_account']); //
                $templateProcessor->setValue('customer_customer_address',$customer_info['customer_address']); //

                $templateProcessor->setValue('funeral_1',$result_order['funeral']=='墓穴葬'?'√':''); //
                $templateProcessor->setValue('funeral_2',$result_order['funeral']=='树葬'?'√':''); //
                $templateProcessor->setValue('funeral_3',$result_order['funeral']=='草坪葬'?'√':''); //
                $templateProcessor->setValue('funeral_4',$result_order['funeral']=='花坛葬'?'√':''); //
                $templateProcessor->setValue('funeral_5',$result_order['funeral']=='壁葬'?'√':''); //
                $templateProcessor->setValue('funeral_6',$result_order['funeral']=='4'?'√':''); //
                $templateProcessor->setValue('funeral_7',$result_order['funeral']=='其他'?'√':$result_order['funeral']); // 单穴、双穴合墓、多穴合墓

                $templateProcessor->setValue('tomb_region_qu',$tomb_address);//所在区域
                $templateProcessor->setValue('tomb_num',$result_order['tomb_num']);  // 墓位编号

                $templateProcessor->setValue('tomb_regulation_1',$result_order['tomb_regulation']==1?'√':''); // 单穴、双穴合墓、多穴合墓
                $templateProcessor->setValue('tomb_regulation_2',$result_order['tomb_regulation']==2?'√':''); // 单穴、双穴合墓、多穴合墓
                $templateProcessor->setValue('tomb_regulation_3',$result_order['tomb_regulation']==3?'√':''); // 单穴、双穴合墓、多穴合墓

                $templateProcessor->setValue('closing_price',$result_order['closing_price']); // 总计
                $templateProcessor->setValue('closing_price_num',convertAmountToCn($result_order['closing_price'],0)); // 总计

                $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
                $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
                $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日

                break;
            case 4:
                if ($result_order['tomb_typei']==0){
                    $templateProcessor = new TemplateProcessor('document/contract/shangpinmu.docx');
                    $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号

                    $templateProcessor->setValue('customer_buyer_name',$customer_info['buyer_name']); //
                    $templateProcessor->setValue('customer_buyer_phone',$customer_info['buyer_phone']); //
                    $templateProcessor->setValue('customer_customer_account',$customer_info['customer_account']); //
                    $templateProcessor->setValue('customer_customer_address',$customer_info['customer_address']); //

                    $templateProcessor->setValue('funeral_1',$result_order['funeral']=='墓穴葬'?'√':''); //
                    $templateProcessor->setValue('funeral_2',$result_order['funeral']=='树葬'?'√':''); //
                    $templateProcessor->setValue('funeral_3',$result_order['funeral']=='草坪葬'?'√':''); //
                    $templateProcessor->setValue('funeral_4',$result_order['funeral']=='花坛葬'?'√':''); //
                    $templateProcessor->setValue('funeral_5',$result_order['funeral']=='壁葬'?'√':''); //
                    $templateProcessor->setValue('funeral_6',$result_order['funeral']=='4'?'√':''); //
                    $templateProcessor->setValue('funeral_7',$result_order['funeral']=='其他'?'√':$result_order['funeral']); // 单穴、双穴合墓、多穴合墓

                    $templateProcessor->setValue('tomb_region_qu',$tomb_address);//所在区/位置
                    $templateProcessor->setValue('tomb_num',$result_order['tomb_num']);  // 墓位编号

                    $templateProcessor->setValue('tomb_regulation_1',$result_order['tomb_regulation']==1?'√':''); // 单穴、双穴合墓、多穴合墓
                    $templateProcessor->setValue('tomb_regulation_2',$result_order['tomb_regulation']==2?'√':''); // 单穴、双穴合墓、多穴合墓
                    $templateProcessor->setValue('tomb_regulation_3',$result_order['tomb_regulation']==3?'√':''); // 单穴、双穴合墓、多穴合墓

                    $templateProcessor->setValue('closing_price',$result_order['closing_price']); // 总计
                    $templateProcessor->setValue('closing_price_num',convertAmountToCn($result_order['closing_price'],0)); // 总计

                    $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
                    $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
                    $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日


                    $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
                    $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
                    $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日
                }else {
                    $deceased_info = ArchivesDeceasedModel::where(['customer_id'=>$customer_info['id']])->find();

                    $templateProcessor = new TemplateProcessor('document/contract/guhuijicunxieyi.docx');
                    $templateProcessor->setValue('contract_sn', $contract_sn);//合同编号
                    $templateProcessor->setValue('customer_buyer_name', $customer_info['buyer_name']); //
                    $templateProcessor->setValue('customer_buyer_phone', $customer_info['buyer_phone']); //
                    $templateProcessor->setValue('customer_customer_account', $customer_info['customer_account']); //
                    $templateProcessor->setValue('customer_customer_address', $customer_info['customer_address']); //
                    $templateProcessor->setValue('cart_type', cart_type('cart',$customer_info['cart_type'])); //
                    $templateProcessor->setValue('customer_deceased_name', isset($deceased_info['deceased_name'])?$deceased_info['deceased_name']:''); //

                    $templateProcessor->setValue('tomb_region_qu', $tomb_address);//所在区域
                    $templateProcessor->setValue('tomb_num', $result_order['tomb_num']);  // 墓位编号

                    $jicun_shichang = unixtime_to_date($result_order['add_time'],'Y-m-d').'至'.
                        unixtime_to_date(unixtime_to_date_inc($result_order['add_time'],intval($result_order['deposit_storage'])),'Y-m-d');

                    $templateProcessor->setValue('jicun_shichang',$jicun_shichang ); // 服务年
                    $templateProcessor->setValue('jicun_nian', $result_order['deposit_storage']); // 服务年
                    $templateProcessor->setValue('youhui', $result_order['closing_price']==1500?'1500/5年':($result_order['discount_price']!=0?'免费寄存'.$result_order['discount_price'].'年':"无")); // 服务年
                    $templateProcessor->setValue('danjia', $result_order['selling_price']); // 服务年
                    $templateProcessor->setValue('yingshou_price',  $result_order['selling_price']* $result_order['deposit_storage']); // 应收金额
                    $templateProcessor->setValue('yingshou_heji', $result_order['selling_price']* $result_order['deposit_storage']); // 应收金额合计
                    $templateProcessor->setValue('shiji_price',$result_order['closing_price']); // 实际
                    $templateProcessor->setValue('shiji_heji', round($result_order['closing_price'],2)); // 实际合计
                    
                    $templateProcessor->setValue('nian', date('Y', $sign_time ? $sign_time : time())); // 年
                    $templateProcessor->setValue('yue', date('m', $sign_time ? $sign_time : time())); // 月
                    $templateProcessor->setValue('ri', date('d', $sign_time ? $sign_time : time())); // 日
                }
                break;
        }
        $file =  'upload/archives/'.$result_order['tomb_num'].'/contract/'.$contract_sn;
        if (!file_exists('upload/archives/'.$result_order['tomb_num'].'/')){
            mkdir('upload/archives/'.$result_order['tomb_num'].'/');
        }
        if (!file_exists('upload/archives/'.$result_order['tomb_num'].'/contract/')){
            mkdir('upload/archives/'.$result_order['tomb_num'].'/contract/');
        }
//        $file = 'temp/doc/'.$contract_sn.'-'.$result_order['tomb_num'].'';
        $templateProcessor->saveAs($file.'.docx');
        $phpWord = \PhpOffice\PhpWord\IOFactory::load($file.'.docx');
        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
        $xmlWriter ->save($file.'.html');//$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].
        return ['doc'=>'/'.$file.'.docx','html'=>'/'.$file.'.html'];
    }

}